#include "AnimatedObject.h"


AnimatedObject::AnimatedObject()
{
	isPlaying=false;
	mIterFrames=0;
	mDelay=0;
	mSpeed=5;
	mPosX=50;
	mPosY=50;
	mVisibleFrameWhenNotPlaying=0;
}

AnimatedObject::~AnimatedObject()
{
	//
}

void AnimatedObject::Render()
{
	if(isPlaying)
	{
		mDelay++;
		GraphicsUtil::getInstance().Render_SDLSurface(mDisplay,mFrames.at(mIterFrames), mPosX,mPosY);
		if(mDelay>mSpeed)
		{
			if(mIterFrames<mFrames.size()-1)
			{
				mIterFrames++;
			}
			else
			{
				mIterFrames=0;
				isPlaying=false;
			}
			mDelay=0;
		}
	}
	else if(mVisibleWhenNotPlaying==true)
	{
		GraphicsUtil::getInstance().Render_SDLSurface(mDisplay,mFrames.at(mVisibleFrameWhenNotPlaying), mPosX,mPosY);
	}
}

void AnimatedObject::setPlaying()
{
	if(!isPlaying)
	{
		isPlaying=true;
	}
}

void AnimatedObject::AddFrame(SDL_Surface* frame)
{
	mFrames.push_back(frame);
}

void AnimatedObject::setScreen(SDL_Surface &screen)
{
	mDisplay=&screen;
}

void AnimatedObject::setPosition(int x, int y)
{
	mPosX=x;
	mPosY=y;
}

void AnimatedObject::setSpeed(int speed)
{
	mSpeed=speed;
}